import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		//新增
		formData:[
			{ label: '被复制模板名称',	name: 'from_temp_code', 	half:true, required:true, type: 'select', 	loading:true, idStr:'temp_code' },
			{ label: '模板编码',			name: 'temp_code', 			half:true, required:true },
			{ label: '模板名称',			name: 'temp_name', 			half:true, required:true },
			{ label: '英文名称',			name: 'temp_name_en', 		half:true, required:true },
			{ label: '排序',				name: 'sort', 				half:true, type: 'number' },
			{ label: '备注',				name: 'remark', 			full:true, type: 'textarea' },
		]
	}
	
	model = {}
	
	open = rows => {
		const { uuid } = rows
		this.modal.open({ formRef:this.formRef })
		this.submit = { uuid }
		this.getModalSelect()
		this.formRef.setValue(rows)
	}
	
	// 获取弹窗下拉框数据
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, 'from_temp_code', ()=>{
			$cache.then( async f => {
				// 模板名称
				await $fn.setRowc(formData, 'from_temp_code',  async () =>  f.getCache({ api: 'qt_template'}))
				//
				this.setState({ formData })
			})
		})
	}

	render(){
		return FormModal.call(this,{ title:'新增', labelWidth:'s8', api: 'qt-comp-template/cptemp' })
	}
}

export default Index